package eureka.domain.comment;

import java.io.Serializable;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

import eureka.domain.account.WebsiteUser;
import net.sf.json.JSON;
import net.sf.json.JSONSerializer;

public class Comment implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private long cID;
	private WebsiteUser CommentUser;
	private String Title;
	private String Content;
	private Timestamp CommentTime;
	private Timestamp ReplyTime;
	private CommentState commentState;
	private WebsiteUser ReplyUser;
	private String ReplyContent;

	// non-paramter constructor
	public Comment() {
		super();
	}

	// constructor
	public long getCID() {
		return this.cID;
	}

	public void setCID(long cID) {
		this.cID = cID;
	}

	public WebsiteUser getCommentUser() {
		return this.CommentUser;
	}

	public void setCommentUser(WebsiteUser CommentUser) {
		this.CommentUser = CommentUser;
	}

	public WebsiteUser getReplyUser() {
		return this.ReplyUser;
	}

	public void setReplyUser(WebsiteUser ReplyUser) {
		this.ReplyUser = ReplyUser;
	}

	public String getTitle() {
		return this.Title;
	}

	public void setTitle(String Title) {
		this.Title = Title;
	}

	public String getContent() {
		return this.Content;
	}

	public void setContent(String Content) {
		this.Content = Content;
	}

	public Timestamp getCommentTime() {
		return this.CommentTime;
	}

	public String getFormattedCommentTime() {
		if (this.CommentTime == null)
			return "";
		return (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(this.CommentTime);
	}

	public void setCommentTime(Timestamp CommentTime) {
		this.CommentTime = CommentTime;
	}

	public Timestamp getReplyTime() {
		return this.ReplyTime;
	}

	public String getFormattedReplyTime() {
		if (this.ReplyTime == null)
			return "";
		return (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(this.ReplyTime);
	}

	public void setReplyTime(Timestamp ReplyTime) {
		this.ReplyTime = ReplyTime;
	}

	public CommentState getCommentState() {
		return this.commentState;
	}

	public void setCommentState(CommentState CommentState) {
		this.commentState = CommentState;
	}

	public void setCommentState(short StateCode) {
		this.commentState = CommentState.fromCode(StateCode);
	}

	public String getReplyContent() {
		return ReplyContent;
	}

	public void setReplyContent(String ReplyContent) {
		this.ReplyContent = ReplyContent;
	}
	
	public static Comment getDefaultEmpty() {
		Comment c=new Comment();
		c.cID = 0;
		c.CommentUser = WebsiteUser.getDefaultEmpty();
		c.Title = "";
		c.Content = "";
		c.CommentTime = null;
		c.ReplyTime = null;
		c.commentState = CommentState.Unhandled;
		c.ReplyUser = WebsiteUser.getDefaultEmpty();
		c.ReplyContent = "";
		return c;
	}

	public JSON toJSON() {
		return JSONSerializer.toJSON(this);
	}
}
